package com.wanlian.router.net.storage;

import android.content.Context;

import com.smart.android.storage.DataStorageSystem;

/**
 * Author: 0xC4.
 * Email: fvaryu@163.com.
 * Date:  2018/8/7.
 */
public interface HttpStorage {
    String FILE_NAME = "smart_sp_net";
    HttpStorage DEFAULT = new HttpStorage() {

        @Override
        public void setDomain(Context context, String host) {
            DataStorageSystem.get(context, FILE_NAME)
                    .write("_app.host", host);
        }

        @Override
        public String getDomain(Context context) {
            return DataStorageSystem.get(context, FILE_NAME)
                    .readString("_app.host");
        }

        @Override
        public void setServerTime(Context context, long time) {
            DataStorageSystem.get(context, FILE_NAME)
                    .write("_app.server_time", time);
        }

        @Override
        public long getServerTime(Context context) {
            long time = DataStorageSystem.get(context, FILE_NAME)
                    .readLong("_app.server_time");
            return time == 0 ? System.currentTimeMillis() : time;
        }

    };


    void setDomain(Context context, String host);
    String getDomain(Context context);

    void setServerTime(Context context, long time);
    long getServerTime(Context context);

}
